Using resource dictionaries

A resource dictionary is a collection of resource IDs pointing to resources. By default resource dictionaries are present in the root nodes of all prefabs but you can add a resource dictionary to any node.

A node can access all resource IDs in its own resource dictionary and in resource dictionaries defined in its ascendant nodes. You can assign resource IDs as values for resource properties and they are shown in Kanzi Studio with the syntax RscID → Resource.

You can make resources local to any node. By adding a resource to a scope of a node you add a resource ID entry to the resource dictionary of that node. A resource ID is an identifier that abstracts a resource from where it is used.

Adding a resource dictionary to a node

To add a resource dictionary to a node, in the Project press Alt and right-click a node and select Resource Dictionary.

Viewing the content of a resource dictionary

To view the content of a resource dictionary:

  1. In the Project select the node the content of whose resource dictionary you want to see in the Dictionaries. Resources listed in the Dictionaries are color-coded:

Viewing and activating locales and themes

To view and activate locales and themes, in the Dictionaries click Locales and Themes to enable the viewing of localization tables and theme groups, and for each localization table and theme group select the locale and theme you want to see in the Preview.

Adding a resource to a resource dictionary

To add a resource to a resource dictionary:

  1. Add a resource dictionary to a node. See Adding a resource dictionary to a node.
  2. In the Dictionaries click + Add Resource and select:

Using a kzb URL for a resource in a resource dictionary

You can use a kzb URL to point to resources in another Kanzi Studio project.

To use a kzb URL for a resource in a resource dictionary:

  1. In the Dictionaries double-click the cell for the resource for which you want to use a kzb URL and in the dropdown menu select < URL >.
  2. In the cell enter the kzb URL of the resource you want to use.
    For example, to use a font from another Kanzi Studio project, enter the kzb URL pointing to that font.

Using resource dictionaries in the API

To create a resource dictionary:

// Create a resource dictionary.
ResourceDictionarySharedPtr dictionary = ResourceDictionary::create(domain, "Dictionary");

To add content to a resource dictionary:

// Add resources to a resource dictionary.
dictionary->add(ResourceID("red icon"), texture);
dictionary->add(ResourceID("blue icon"), "kzb://my_project/Textures/Blue Icon");

To get resources from a resource dictionary:

// Acquire resources from a resource dictionary.
ResourceSharedPtr redIcon = dictionary->acquire(ResourceID("red icon"));
ResourceSharedPtr blueIcon = dictionary->acquire(ResourceID("blue icon"));

To change the resource dictionary of a node:

// Change the resource dictionary of a node.
node->setResourceDictionary(dictionary);

To extend the existing resource dictionary of a node:

// Extend the existing resource dictionary of a node with a nested resource dictionary.
node->addResourceDictionary(dictionary);

For details, see the ResourceDictionary class in the API reference.

See also

Resource management

Localization

Theming your applications